package com.tanger.permission.mapper.permission;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanger.permission.entity.permission.EntityRolePermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据持久接口层
 */
public interface RolePermissionMapper extends BaseMapper<EntityRolePermission>{

	/**
	 * 查询列表
	 * @param paramMap
	 * @return
	 */
	List<LinkedHashMap<String, Object>> queryRolePermission(Map<String, Object> paramMap);


	/**
	 * 查询详情
	 * @param id
	 * @return
	 */
	EntityRolePermission RolePermissionInfo(@Param("id") Long id);

	/**
     * 查列表
	 * @param paramMap
     * @return
     */
	List<EntityRolePermission> queryRolePermissionList(Map<String, Object> paramMap);

	/**
	 * 新增角色权限
	 * @param rolePermission
	 * @return
	 */
	int insertRolePermission(EntityRolePermission rolePermission);

	/**
	 * 删除角色权限
	 * @param roleId
	 * @return
	 */
	int deleteRolePermission(@Param("roleId") Long roleId);

	/**
	 * 删除角色权限
	 * @param ids
	 * @return
	 */
	int deleteRolePermissionByIds(@Param("ids") List<Long> ids);

	/**
	 * 查询列表
	 * @param roleId
	 * @return
	 */
	@Select({"<script>",
			"SELECT " +
				"rp.id  AS id , rp.role_id AS roleId , rp.permission_id AS permissionId , m.menu_code AS menuCode , " +
				"m.menu_type AS menuType , m.menu_name AS menuName , m.menu_path AS menuPath ,m.menu_component AS menuComponent , " +
				"m.menu_sequence AS menuSequence , m.menu_status AS menuStatus , m.parent_id AS parentId" +
			" FROM brt_base_role_permission rp LEFT JOIN t_sys_menu m ON rp.permission_id = m.id" +
			" WHERE 1 = 1 " +
			"<if test='roleId != null'>" +
				"AND rp.role_id = #{roleId}" +
			"</if>",
			"</script>"
	})
	List<LinkedHashMap<String, Object>> queryRolePermissionByRoleId(Long roleId);
}
